﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Media;
using System.IO;

namespace Megaman
{
    class StageManager
    {
        public List<Stage> stages;
        public int currentStage = -1;
        public ContentManager Content
        {
            get { return content; }
        }
        ContentManager content;
        StageSelect stageSelect;
        Stage loadedStage;
        IServiceProvider service;

        public StageManager(IServiceProvider service)
        {
            
            stages = new List<Stage>(9);
            this.service = service;
            content = new ContentManager(service, "Content");
            stages.Add(new Stage(service,"Mountain", "Stages/mountain", this));
            stages.Add(new Stage(service,"Ocean", "Stages/ocean", this));
            stages.Add(new Stage(service,"Cave", "Stages/cave", this));
            stages.Add(new Stage(service, "Jungle", "Stages/jungle", this));
            stages.Add(new Stage(service, "Power Plant", "Stages/powerplant", this));
            stages.Add(new Stage(service, "Metal Plant", "Stages/metalplant", this));
            stages.Add(new Stage(service, "Cyberspace", "Stages/cyberspace", this));
            stages.Add(new Stage(service, "Missile Silo", "Stages/silo", this));

            stages[0].nextStages.Add(stages[1]);
            stages[1].nextStages.Add(stages[2]);

            stages[0].addBoss(new Boss(stages[0],"Bosses/Airman/","AIRMAN"));
            stages[1].addBoss(new Boss(stages[1], "Bosses/Diveman/","DIVEMAN"));
            stages[2].addBoss(new Boss(stages[2], "Bosses/Shadowman/","SHADOWMAN"));
            stages[3].addBoss(new Boss(stages[3], "Bosses/Snakeman/","SNAKEMAN"));



            stages[0].Available = true;
            stages[1].Available = true;
            stages[2].Available = true;
            stages[3].Available = true;




            LoadStage(-1);
        }

        public void LoadStage(int index)
        {
            currentStage = index;
            if (currentStage == -1)
            {
                if (stageSelect == null)
                    stageSelect = new StageSelect(this, service);

            }
            else
            {
                stageSelect.Dispose();
                stageSelect = null;
                stages[currentStage].Lives = 3;
                stages[currentStage].LoadNextLevel();
            }
        }

        public void UnloadStage()
        {
            LoadStage(-1);
        }

        public void Update(GameTime gameTime)
        {
            if (currentStage == -1)
                stageSelect.Update(gameTime);
            else
                stages[currentStage].Update(gameTime);
        }

        public void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            if (currentStage == -1)
                stageSelect.Draw(spriteBatch, gameTime);
            else
                stages[currentStage].Draw(spriteBatch, gameTime);
        }
    }
}
